@page "/log-test"
@inject LogCacheService LogCacheService

<PageTitle>日志测试</PageTitle>

<div class="container mt-4">
    <h3>全局日志缓存队列测试</h3>
    
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="mb-0">测试日志生成</h5>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-6">
                    <button class="btn btn-primary mb-2" @onclick="GenerateTraceLog">生成Trace日志</button>
                    <button class="btn btn-info mb-2" @onclick="GenerateDebugLog">生成Debug日志</button>
                    <button class="btn btn-success mb-2" @onclick="GenerateInfoLog">生成Info日志</button>
                </div>
                <div class="col-md-6">
                    <button class="btn btn-warning mb-2" @onclick="GenerateWarningLog">生成Warning日志</button>
                    <button class="btn btn-danger mb-2" @onclick="GenerateErrorLog">生成Error日志</button>
                    <button class="btn btn-dark mb-2" @onclick="GenerateCriticalLog">生成Critical日志</button>
                </div>
            </div>
            
            <div class="mt-3">
                <button class="btn btn-outline-secondary" @onclick="GenerateMultipleLogs">批量生成10条测试日志</button>
            </div>
        </div>
    </div>
    
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">日志查看器</h5>
        </div>
        <div class="card-body">
            <LogViewer />
        </div>
    </div>
</div>

@code {
    private int logCounter = 1;
    
    private void GenerateTraceLog()
    {
        LogWrapper.Trace($"这是第{logCounter++}条Trace级别测试日志");
    }
    
    private void GenerateDebugLog()
    {
        LogWrapper.Debug($"这是第{logCounter++}条Debug级别测试日志");
    }
    
    private void GenerateInfoLog()
    {
        LogWrapper.Information($"这是第{logCounter++}条Information级别测试日志");
    }
    
    private void GenerateWarningLog()
    {
        LogWrapper.Warning($"这是第{logCounter++}条Warning级别测试日志");
    }
    
    private void GenerateErrorLog()
    {
        try
        {
            // 模拟一个异常
            throw new InvalidOperationException($"这是第{logCounter}条测试异常");
        }
        catch (Exception ex)
        {
            LogWrapper.Error($"这是第{logCounter++}条Error级别测试日志", ex);
        }
    }
    
    private void GenerateCriticalLog()
    {
        LogWrapper.Critical($"这是第{logCounter++}条Critical级别测试日志");
    }
    
    private void GenerateMultipleLogs()
    {
        for (int i = 0; i < 10; i++)
        {
            var level = (LogLevel)(i % 6);
            var message = $"批量生成的第{i+1}条{level}级别测试日志";
            
            switch (level)
            {
                case LogLevel.Trace:
                    LogWrapper.Trace(message);
                    break;
                case LogLevel.Debug:
                    LogWrapper.Debug(message);
                    break;
                case LogLevel.Information:
                    LogWrapper.Information(message);
                    break;
                case LogLevel.Warning:
                    LogWrapper.Warning(message);
                    break;
                case LogLevel.Error:
                    LogWrapper.Error(message);
                    break;
                case LogLevel.Critical:
                    LogWrapper.Critical(message);
                    break;
            }
        }
        logCounter += 10;
    }
}